package com.alix.paymoney.presenter.impl;

import com.alix.paymoney.entity.ChannelBean;
import com.alix.paymoney.http.CallManager;
import com.alix.paymoney.http.HttpManager;
import com.alix.paymoney.http.OnResponseListener;
import com.alix.paymoney.presenter.ChannelPresenter;
import com.alix.paymoney.utils.Loger;
import com.alix.paymoney.view.ChannelListView;

import retrofit2.Call;

/**
 * Created by wushiqian on 2017/11/14.
 */

public class ChannelPresenterImpl extends BasePresenterImpl<ChannelListView> implements ChannelPresenter {
    public ChannelPresenterImpl(ChannelListView channelListView) {
        super(channelListView);
    }

    @Override
    public void getChannelList(String type) {
        Call<ChannelBean> channelList = HttpManager.getInstance().getApiService().getChannelList(type);
        CallManager.getInstance().addQueue(channelList, new OnResponseListener<ChannelBean>() {
            @Override
            public void Success(ChannelBean o) {

                getView().getChannelSuccess(o.getRows());
                getView().stopSwipRefresh();
            }

            @Override
            public void onFailed(int errorCode, String errorInfo) {
                getView().getChannelError(errorCode, errorInfo);
                getView().stopSwipRefresh();
                Loger.e(errorCode + "获取频道列表" + errorInfo);
            }

            @Override
            public void onException(String msg) {
                Loger.e("获取频道列表" + msg);
                getView().showTips(msg);
                getView().stopSwipRefresh();
            }
        });
    }
}
